<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<script src="../js/mui.js"></script>
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>
	</head>
	<style>
		.item1 {
			width: 100%;
			display: flex;
		}

		.item1>img {
			display: block;
			width: 7rem;
			height: 7rem;
			background-size: cover;
		}

		.li_item li:nth-child(7)>.item1>img {
			width: 190px;
		}

		.spntwo,
		.spnone {
			white-space: pre-wrap;
			font-size: 15px;
		}

		.item_title {
			margin-left: 0.9375rem;
		}
	</style>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">浏览记录</h1>
		</header>
		<div class="mui-content">
			<!-- 推荐文章 -->
			<ul class="mui-table-view li_item" style="margin-bottom: 50px;">
				<!--  推荐文章内容  -->
				<!-- <li class="mui-table-view-cell item">
					<a href="./html/articles.html">
						<div class="item1">
							<img src="${item.img}" alt="">
							<div class="item_title" style="display:flex; flex-direction: column;
				justify-content: space-between;">
								<span>${item.title}</span>
								<span>${item.time}</span>
							</div>
						</div>
					</a>
				</li> -->
			</ul>
		</div>
		<div class="mui-content" style="margin-top: 0;padding-top:0; display: flex; justify-content: center;">
			<button class="btn">删除历史记录</button>
		</div>
	</body>
	<script>
		mui.ajax('http://192.168.0.111:3000/article/search', {
			dataType: 'json', //服务器返回json格式数据
			type: 'get', //HTTP请求类型	              
			success: function(res) {
				//服务器返回响应，根据响应结果，分析是否登录成功；
				let data = res.data
				let history = JSON.parse(localStorage.getItem('history')) 
				console.log(history);
				data.forEach(item => {
					if (history == item.title) {
						let module = `
					<li class="mui-table-view-cell item">
						<a href="./html/articles.html?id=${item.id}">
							<div class="item1">
								<img src="${item.img}" alt="">
								<div class="item_title" style="display:flex; flex-direction: column;justify-content: space-between;">
									<span class="spntwo">${item.title}</span>
									<span class="spnone">${item.time}</span>
								</div>
							</div>
						</a>
					</li>
					`
						$('.li_item').append(module)
					}
				})

				// 点击删除内容
				$('.btn').on('tap', function() {
					$('.li_item').html('')
					localStorage.removeItem('history')
				})
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			}
		});
	</script>
</html>